package com.xzh.gulimall.order.service.impl;

import com.rabbitmq.client.Channel;
import com.xzh.gulimall.order.entity.OrderEntity;
import com.xzh.gulimall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xzh.common.utils.PageUtils;
import com.xzh.common.utils.Query;

import com.xzh.gulimall.order.dao.OrderItemDao;
import com.xzh.gulimall.order.entity.OrderItemEntity;
import com.xzh.gulimall.order.service.OrderItemService;


@Service("orderItemService")
//@RabbitListener(queues = {"hello-java-queue"})
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderItemEntity> page = this.page(
                new Query<OrderItemEntity>().getPage(params),
                new QueryWrapper<OrderItemEntity>()
        );

        return new PageUtils(page);
    }

    /*
    * queues:声明所需要监听 所有队列
    *
    * 参数可以写以下类型
    * 1、Message msg,原生消息详细信息，头+体
    * 2、T<发送的消息类型>
    * 3、Channel 当前传输数据的通道*/


   /* @RabbitHandler
    public void recieveMessage(Message msg,
                               OrderEntity content,
                               Channel channel)  {
        byte[] body = msg.getBody();
        MessageProperties messageProperties = msg.getMessageProperties();
        System.out.println("1接收到参数为 =="+msg);
        //按照channel内接收的消息自增，从1开始编号
        long deliveryTag = msg.getMessageProperties().getDeliveryTag();


        try {
            if(deliveryTag%2==0){
                //签收消息
                // 第一个参数指定签收哪条消息哪条消息
                //第二个参数表示是否批量签收
                channel.basicAck(deliveryTag,false);
            }else{
                //拒绝签收消息
                //第三个参数 requeue   false表示丢弃，true表示重新入队
                //第二个参数 表示是否批量
                channel.basicNack(deliveryTag,false,true);
                //第二个参数 requeue   false表示丢弃，true表示重新入队
                //channel.basicReject(deliveryTag,false);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @RabbitHandler
    public void reieveMessage2(Long num)
    {

        System.out.println("2接收数值类型的消息为==="+num);
    }*/

}